﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FiguresListDraw
{
    class Rectangle : Figure
    {
        #region Constructors

        /// <summary>
        /// Constructor of the class Rectangle  - with two parameters
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public Rectangle(int width, int height)
            : this(width, height, false, 0)
        { }

        /// <summary>
        /// /// <summary>
        /// Constructor of the class Rectangle - with three parameters
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="filling"></param>
        public Rectangle(int width, int height, bool filling)
            : this(width, height, filling, 0)
        { }

        /// <summary>
        /// /// <summary>
        /// Constructor of the class Rectangle - with four parameters
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="filling"></param>
        /// <param name="indent"></param>
        public Rectangle(int width, int height, bool filling, int indent)
        {
            this.Width = width;
            this.Height = height;
            this.Indentation = indent;
            this.IsFilling = filling;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Width of rectangle
        /// </summary>
        public int Width
        {
            get { return m_width; }
            set { m_width = value; }
        }

        /// <summary>
        /// Height of rectangle
        /// </summary>
        public int Height
        {
            get { return m_height; }
            set { m_height = value; }
        }

        #endregion

        #region Overrided methods Draw and private method DrawLine

        public override void Draw()
        {
            string strIndentation = String.Format("{0, " + Indentation + "}", " ");
            string strPromegut = strIndentation + "*" +
               String.Format("{0, " + -1 * (Width - 2) + "}", " ") + "*";

            if (IsFilling)
            {
                for (int i = 0; i < Width; i++)
                {
                    DrawLine(strIndentation);
                }
            }
            else
            {
                DrawLine(strIndentation);

                for (int i = 1; i < Height - 1; i++)
                {
                    Console.Write(strPromegut);
                    Console.WriteLine();
                }

                DrawLine(strIndentation);
            }
        }

        private void DrawLine(string s)
        {
            Console.Write(s);

            for (int i = 0; i < Width; i++)
            {
                Console.Write("*");
            }

            Console.WriteLine();
        }
        
        #endregion

        #region Fields

        private int m_width;
        private int m_height;

        #endregion
    }
}
